﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using Wp.BLL;
using Wp.DAL;


/// <summary>
/// Summary description for AddComment
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
[System.Web.Script.Services.ScriptService]
public class AddComment : System.Web.Services.WebService
{

    public AddComment()
    {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

    [WebMethod]
    public string HelloWorld()
    {
        return "Hello World";
    }
    [WebMethod(EnableSession = true)]
    public string AddPostComment(int PostId, int ParentId, string Comment, string Email, string Name, string Website, int Validate)
    {
        if (Session["result"] != null && Session["result"].ToInt() == Validate)
        {
            TblCommentsEntity item = new TblCommentsEntity();
            item.Id = -1;
            item.PostId = PostId;
            item.Author = Name;
            item.Email = Email;
            item.IP = "";
            item.Content = Comment;
            item.ParentId = ParentId;
            item.CreatedDate = DateTime.Now;
            item.Approved = "new";
            if (User.Identity.IsAuthenticated)
                item.CreatedBy = User.Identity.Name;
            else item.CreatedBy = "";
            TblCommentsManager.CreateInstant().InsertUpdate(item);
            return "true";
        }
        return "";
    }
    [WebMethod(EnableSession = true)]
    public string ValidateCaptcha(int Validate)
    {
        string result = "Câu trả lời sai";
        if (Session["result"] != null)
        {
            if (Session["result"].ToInt() == Validate)
                result = "";
        }
        return result;
    }
    [WebMethod]
    public bool Delete(int Id)
    {
        bool result = false;
        if (User.Identity.IsAuthenticated)
        {
            TblCommentsManager.CreateInstant().Delete(Id);
            result = true;
        }
        return result;
    }
}
